﻿using System;

namespace Calculator___ConsoleApp {
    class Program {
        static void Main(string[] args) {
            String Operand1, Operand2, Operator;
            bool Condition;
            double PreviousOperand = 0, PostOperand = 0, Result = 0;
            Console.WriteLine("Calculator");
            do {
                Condition = false;
                try {
                    Console.Write("Previous Operand: ");
                    Operand1 = Console.ReadLine();
                    PreviousOperand = Double.Parse(Operand1);
                }
                catch (FormatException e) {
                    Condition = true;
                    Console.WriteLine("Input operand was not in a correct format (xxx or xxx.xxx, x = 0 ~ 9).");
                }
            } while (Condition);
            do {
                Condition = false;
                try {
                    Console.Write("Post Operand: ");
                    Operand2 = Console.ReadLine();
                    PostOperand = Double.Parse(Operand2);
                }
                catch (FormatException e) {
                    Condition = true;
                    Console.WriteLine("Input operand was not in a correct format (xxx or xxx.xxx, x = 0 ~ 9).");
                }
            } while (Condition);
            do {
                Condition = false;

                Console.Write("Operator: ");
                Operator = Console.ReadLine();
                switch (Operator[0]) {
                    case '+':
                        Result = PreviousOperand + PostOperand;
                        break;
                    case '-':
                        Result = PreviousOperand - PostOperand;
                        break;
                    case '*':
                        Result = PreviousOperand * PostOperand;
                        break;
                    case '/':
                        Result = PreviousOperand / PostOperand;
                        break;
                    default:
                        Condition = true;
                        Console.WriteLine("Input operator was not in a correct format (+, -, *, /).");
                        break;
                }

            } while (Condition);
            Console.WriteLine($"Expression: {PreviousOperand} {Operator[0]} {PostOperand}");
            Console.WriteLine($"Result: {Result}");
        }
    }
}
